/*
 * Copyright (c) 2019. Dxxld@qq.com. All rights reserved.
 */

package com.wauil.keenote.algorithm;

/**
 * @Description: 选择排序
 * @Author: kee
 * @Email: dxxld@qq.com
 * @Date: 2019/12/20 11:45
 * @Version: 1.0
 */
public class ChoiceSort {
    public void sort(int[] array) {
        //每次选择最小的值放在最前面
        for (int i = 0; i < array.length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[min] > array[j]) {
                    min = j;
                }
            }
            if (min != i) {
                int temp = array[min];
                array[min] = array[i];
                array[i] = temp;
            }
        }
    }
}
